package com.zcsy.manage.service.mall.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zcsy.manage.model.mall.CategoryAttr;
import com.zcsy.manage.model.mall.CategoryAttrValue;
import com.zcsy.manage.persistence.mall.CategoryAttrDao;
import com.zcsy.manage.service.mall.ICategoryAttrService;

@Service
public class CategoryServiceImpl implements ICategoryAttrService {

	@Autowired
	private CategoryAttrDao categoryAttrDao;
	@Override
	public int insert(CategoryAttr attr) {
		return categoryAttrDao.insert(attr);
	}

	@Override
	public int update(CategoryAttr attr) {
		CategoryAttr oldAttr = categoryAttrDao.selectCategoryAttrById(attr.getId());
		
		oldAttr.setName(attr.getName());
		oldAttr.setCategoryId(attr.getCategoryId());
		oldAttr.setUserAccount(attr.getUserAccount());
		oldAttr.setInputType(attr.getInputType());
		oldAttr.setUpdateTime(attr.getUpdateTime());
		
		return categoryAttrDao.update(oldAttr);
	}

	@Override
	public CategoryAttr selectCategoryAttrById(String id) {
		return categoryAttrDao.selectCategoryAttrById(id);
	}

	@Override
	public int deleteByPrimaryKey(String id) {
		return categoryAttrDao.deleteByPrimaryKey(id);
	}

	@Override
	public List<CategoryAttr> selectByCategoryId(String categoryId) {
		List<CategoryAttr> categoryAttrs = categoryAttrDao.selectByCategoryId(categoryId);
		//获取分类属性的所有属性值付给分类属性categoryAttrValues
		for(CategoryAttr itemAttr : categoryAttrs){
			List<CategoryAttrValue> categoryAttrValues = categoryAttrDao.selectByAttrId(itemAttr.getId());
			itemAttr.setCategoryAttrValues(categoryAttrValues);
		}
		return categoryAttrs;
	}

	@Override
	public List<CategoryAttrValue> selectByAttrId(String attrId) {
		return categoryAttrDao.selectByAttrId(attrId);
	}

	@Override
	public int insertAttrValue(CategoryAttrValue attrValue) {
		return categoryAttrDao.insertAttrValue(attrValue);
	}

	@Override
	public int updateAttrValue(CategoryAttrValue attrValue) {
		return categoryAttrDao.updateAttrValue(attrValue);
	}

	@Override
	public int deleteValueByprimaryKey(String attrValueId) {
		return categoryAttrDao.deleteValueByprimaryKey(attrValueId);
	}

	@Override
	public int deleteValueByAttrId(String attrId) {
		return categoryAttrDao.deleteValueByAttrId(attrId);
	}

}
